<?php

declare(strict_types=1);

namespace App\Entity;

use App\Models\WechatUser;

class WechatUserEntity extends ABaseEntity
{
    /**
     * WechatUserEntity constructor.
     */
    public function __construct(WechatUser $mode)
    {
        $this->model = $mode;
    }

    public function getId(): int
    {
        return (int) $this->model->id;
    }

    public function setId(int $id): void
    {
        $this->model->id = $id;
    }

    public function getOpenid(): string
    {
        return (string) $this->model->openid;
    }

    public function setOpenid(string $openid): void
    {
        $this->model->openid = $openid;
    }

    public function getNickname(): string
    {
        return (string) $this->model->nickname;
    }

    public function setNickname(string $nickname): void
    {
        $this->model->nickname = $nickname;
    }

    public function getSex(): string
    {
        return (string) $this->model->sex;
    }

    public function setSex(string $sex): void
    {
        $this->model->sex = $sex;
    }

    public function getLanguage(): string
    {
        return (string) $this->model->language;
    }

    public function setLanguage(string $language): void
    {
        $this->model->language = $language;
    }

    public function getCity(): string
    {
        return (string) $this->model->city;
    }

    public function setCity(string $city): void
    {
        $this->model->city = $city;
    }

    public function getProvince(): string
    {
        return (string) $this->model->province;
    }

    public function setProvince(string $province): void
    {
        $this->model->province = $province;
    }

    public function getCountry(): string
    {
        return (string) $this->model->country;
    }

    public function setCountry(string $country): void
    {
        $this->model->country = $country;
    }

    public function getHeadimgurl(): string
    {
        return (string) $this->model->headimgurl;
    }

    public function setHeadimgurl(string $headimgurl): void
    {
        $this->model->headimgurl = $headimgurl;
    }

    public function getPrivilege(): string
    {
        return (string) $this->model->privilege;
    }

    public function setPrivilege(string $privilege): void
    {
        $this->model->privilege = $privilege;
    }

    public function getUnionid(): string
    {
        return (string) $this->model->unionid;
    }

    public function setUnionid(string $unionid): void
    {
        $this->model->unionid = $unionid;
    }

    public function getUserId(): int
    {
        return (int) $this->model->user_id;
    }

    public function setUserId(int $user_id): void
    {
        $this->model->user_id = $user_id;
    }

    public function getEnabled(): int
    {
        return (int) $this->model->enabled;
    }

    public function setEnabled(int $enabled): void
    {
        $this->model->enabled = $enabled;
    }

    public function getCreatedAt(): string
    {
        return (string) $this->model->created_at;
    }

    public function setCreatedAt(string $created_at): void
    {
        $this->model->created_at = $created_at;
    }

    public function getUpdatedAt(): string
    {
        return (string) $this->model->updated_at;
    }

    public function setUpdatedAt(string $updated_at): void
    {
        $this->model->updated_at = $updated_at;
    }

    public function getChannelid(): int
    {
        return (int) $this->model->channelid;
    }

    public function setChannelid(int $channelid): void
    {
        $this->model->channelid = $channelid;
    }

    /**
     * @return WechatUserEntity|null
     */
    public static function getUser(int $userid): ?self
    {
        $user = WechatUser::where('user_id', $userid)->first();
        if ($user === null) {
            return null;
        }

        return new self($user);
    }

    /**
     * @return static|null
     */
    public static function findByOpenid(string $openid): ?self
    {
        $user = WechatUser::query()->where('openid', $openid)->first();
        if (empty($user)) {
            return null;
        }
        return new self($user);
    }
}
